<style>
.incomplete_deals
{
	color: red;
}
</style>
<script>
	function viewDealNow(caller, orderId, dealOrderCode)
	{
		var popupHeight = 600;
		var popupWidth = 800;
		var couponUrl = '<?php echo $html->url(array("controller"=>"deal_orders","action"=>"dealCoupon")) ?>';
		wtop = (screen.height/2)-(popupHeight/2);
		wleft = (screen.width/2)-(popupWidth/2);
		
		window.open(URL+couponUrl+'/'+orderId+'/'+dealOrderCode,null,"width="+popupWidth+", height="+popupHeight+", scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, top="+wtop+", left="+wleft);
	}
</script>
<div class="myDealsList index">
<?php
$index->setData($deals, 'DealOrder');

$index->showFields(array(array("title"=>__("Title")),array("created"=>__("Purchased On")),array("quantity"=>__("Quantity")),array("amount"=>__("Amount")),array("codes"=>__("Deal Code(s)"))));
				
$index->sortableFields(array('quantity','amount','created'));

$index->addColumn('title','showDealTitle');
$index->addColumn('created','showCreated');
$index->addColumn('codes','showCodes');

function showDealTitle($record)
{
	return __($record['Deal']['title']);
}
function showCreated($record)
{
	return __(date("Y-m-d",strtotime($record['DealOrder']['created'])));
}
function showCodes($record)
{
	$dealCodes = "";
	if($record['DealOrder']['status'] == DealOrder::STATUS_COMPLETE)
	{
		$dealCodesList = Set::extract($record['DealOrderCode'],'{n}.deal_code');
		//$dealCodes = implode(",  ", $dealCodes);
		$html = ClassRegistry::getObject("view")->loaded["html"];
		foreach($dealCodesList as $dealCode)
		{
			$dealUrl = $html->url(array("controller"=>"deal_orders","action"=>"dealCoupon",$record["DealOrder"]["id"], $dealCode));
			//$dealCodeLink = $html->link($dealCode,$dealUrl,array("escape"=>false,"target"=>"_blank"));
			$dealCodeLink = $html->link($dealCode,"javascript:void(0);",array('onclick'=>'viewDealNow(this,'.$record["DealOrder"]["id"].',"'.$dealCode.'")'));
			$dealCodes .= "<li>".$dealCodeLink."</li>";
		}
		$dealCodes = "<ul>".$dealCodes."</ul>";
	} else {
		$dealCodes = "<span class='incomplete_deals'>".__("Incomplete status")."</span><br>";
		$html = ClassRegistry::getObject("view")->loaded["html"];
		$dealCodes .= $html->link(__("Continue Process"),$html->url(array("controller"=>"deal_orders","action"=>"prepareInvoice",$record["DealOrder"]["id"])),array("escape"=>false));
		
	}
	return $dealCodes;
}

echo $index->display($deals);
?>
</div>